#!/usr/bin/perl -w

use strict;

use Data::Dumper;
use Test::Lono 'no_plan';

BEGIN {
    use_ok( 'Lono::Util::Logger' );
};

module_ok( 'Lono::Util::Logger' );

my $logger = Lono::Util::Logger->new;
isa_ok( $logger, 'Lono::Util::Logger' );

# Test _high_enough function
my @FILTER = qw( d e f g );
my $level = 'd';
ok( Lono::Util::Logger::_high_enough( $level, @FILTER ), "Level within filter range." );
$level = 'c';
ok( !Lono::Util::Logger::_high_enough( $level, @FILTER ), "Level not within filter range." );

# Test _filter_to_level function
my @all_msgs = ();
my @warning_or_higher_msgs = ();

my $debug_msg = {'severity' => LOG_DEBUG, 'message' => 'Debug message.'};
push( @all_msgs, $debug_msg );

my $info_msg = {'severity' => LOG_INFO, 'message' => 'Info message.'};
push( @all_msgs, $info_msg );

my $warning_msg = {'severity' => LOG_WARNING, 'message' => 'Warning message.'};
push( @all_msgs, $warning_msg );
push( @warning_or_higher_msgs, $warning_msg );

my $error_msg = {'severity' => LOG_ERROR, 'message' => 'Error message.'};
push( @all_msgs, $error_msg );
push( @warning_or_higher_msgs, $error_msg );

my $critical_msg = {'severity' => LOG_CRITICAL, 'message' => 'Critical msg.'};
push( @all_msgs, $critical_msg );
push( @warning_or_higher_msgs, $critical_msg );

# Append the messages in a different order
$logger->append( $error_msg );
$logger->append( $info_msg );
$logger->append( $critical_msg );
$logger->append( $debug_msg );
$logger->append( $warning_msg );

my @got_all_msgs = $logger->get_messages;
my @got_warning_or_higher_msgs = $logger->get_messages( LOG_WARNING );

is_deeply_normalized_array( \@got_all_msgs, \@all_msgs, 
                            'Unfiltered message lists match.' );
is_deeply_normalized_array( \@got_warning_or_higher_msgs, 
                            \@warning_or_higher_msgs, 
                            'Filtered messsage lists match.' );

#$logger->debug( 'First debug message' );
#$logger->info( 'First info message' );
#$logger->warning( 'First warn message' );
#$logger->error( 'First error message' );
#$logger->critical( 'First critical message' );


